import { OutputData } from './data-formats';

import {
  Blocks,
  Caret,
  InlineToolbar,
  ReadOnly,
  Sanitizer,
  Saver,
  Styles,
  Toolbar
} from './api';

import { EditorConfig } from './configs';


export interface EditorJSConstructable {
  version: string;
  new(configuration?: EditorConfig | string): EditorJSInstance;
}

export interface EditorJSInstance {

  isReady: Promise<void>;
  blocks: Blocks;
  caret: Caret;
  sanitizer: Sanitizer;
  saver: Saver;
  selection: Selection;
  styles: Styles;
  toolbar: Toolbar;
  inlineToolbar: InlineToolbar;
  readOnly: ReadOnly;

  /**
   * API shorthands
   */

  /**
   * @see Saver.save
   */
  save(): Promise<OutputData>;

  /**
   * @see Blocks.clear
   */
  clear(): void;

  /**
   * @see Blocks.render
   */
  render(data: OutputData): Promise<void>;

  /**
   * @see Caret.focus
   */
  focus(atEnd?: boolean): boolean;

  /**
   * @see Events.on
   */
  on(eventName: string, callback: (data?: never) => void): void;

  /**
   * @see Events.off
   */
  off(eventName: string, callback: (data?: any) => void): void;

  /**
   * @see Events.emit
   */
  emit(eventName: string, data: any): void;

  /**
   * Destroy Editor instance and related DOM elements
   */
  destroy(): void;
}


